package com.gxpt.app.adapter;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.gxpt.app.Constant;
import com.gxpt.app.MessageEvent;
import com.gxpt.app.R;
import com.gxpt.app.base.ListBaseAdapter;
import com.gxpt.app.base.SuperViewHolder;
import com.gxpt.app.bean.assesslist_bean;
import com.gxpt.app.bean.servicelist_bean;
import com.utils.ScreenUtils;
import com.utils.picasso.PicassoUtils;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Lzx on 2016/12/30.
 */

public class servicelist_Adapter extends ListBaseAdapter<servicelist_bean.servicelist> {

    Context context;
    int pic_view_width = 0;
    int pic_view_hight = 0;
    String bid_id = "";
    public servicelist_Adapter(Context context) {
        super(context);
        this.context = context;

        int Sviewwidth  = ScreenUtils.getScreenWidth(context);//
        pic_view_width  = Sviewwidth/8;
        pic_view_hight  = pic_view_width;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_servicelist_list;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        servicelist_bean.servicelist item = mDataList.get(position);

        TextView txt_shop_name = holder.getView(R.id.txt_shop_name);
        txt_shop_name.setText(item.shop_name);

        TextView txt_create_time = holder.getView(R.id.txt_create_time);
        txt_create_time.setText(item.create_time);

        TextView txt_mem_tel = holder.getView(R.id.txt_mem_tel);
        txt_mem_tel.setText(item.mem_tel);

        try {
            ImageView img_shop_logo = holder.getView(R.id.img_shop_logo);
            PicassoUtils.Picasso_Circle(context, Constant.IP+item.shop_logo,pic_view_width,img_shop_logo);
        }catch (Exception e){
            e.printStackTrace();
        }

        ImageView txt_bid_status = holder.getView(R.id.txt_bid_status);
        if(item.bid_status.equals("1")){
            txt_bid_status.setVisibility(View.VISIBLE);
        }else{
            txt_bid_status.setVisibility(View.GONE);
        }

        TextView had_bid = holder.getView(R.id.had_bid);
        if(item.is_show_button>1){
            had_bid.setVisibility(View.GONE);
        }else{
            had_bid.setVisibility(View.VISIBLE);
        }
        had_bid.setTag(item.id);
        had_bid.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bid_id = ""+v.getTag();
                Dialog_y_n();
            }
        });


        TextView txt_bid_amount = holder.getView(R.id.txt_bid_amount);
        txt_bid_amount.setText(item.bid_amount);

        TextView txt_time_limit = holder.getView(R.id.txt_time_limit);
        txt_time_limit.setText(item.time_limit);

        TextView txt_remark = holder.getView(R.id.txt_remark);
        txt_remark.setText(item.remark);

    }


    public void Dialog_y_n(){
        final Dialog dialog=new Dialog(context,R.style.customDialogStyle);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view= LayoutInflater.from(context).inflate(R.layout.dialog_yes_no, null);
        dialog.setContentView(view);
        view.findViewById(R.id.bt1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new MessageEvent(
                        Constant.ACTION_sel_bid,
                        ""+bid_id,
                        ""));
                dialog.dismiss();
            }
        });

        view.findViewById(R.id.bt2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        view.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        Window dialogWindow = dialog.getWindow();
        dialogWindow.setWindowAnimations(R.style.commonAnimDialogStyle);
        dialogWindow.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        dialogWindow.setGravity(Gravity.BOTTOM);
        dialog.show();

    }
}
